package com.csdj.server.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.csdj.server.pojo.Employee;
import com.csdj.server.pojo.RespBean;
import com.csdj.server.pojo.RespPageBean;
import com.csdj.server.pojo.Salary;
import com.csdj.server.service.IEmployeeService;
import com.csdj.server.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: SalarySobCfgController
 * @Author: ZouLi
 * @Description:
 * @Date: 2023/1/11 13:47
 **/
@RestController
@RequestMapping("/salary/sobcfg")
@Api(tags = "员工套账控制器")
public class SalarySobCfgController {

    @Autowired
    private ISalaryService salaryService;

    @Autowired
    private IEmployeeService employeeService;

    @ApiOperation("获取全部员工套账")
    @GetMapping("/getAllEmpSalary")
    public RespPageBean getAllEmpSalary(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer limit) {
        return employeeService.getEmployeeWithSalary(page, limit);
    }

    @ApiOperation(value = "获取全部工资套账")
    @GetMapping("/getAllSalary")
    public List<Salary> getAllSalary(){
        return salaryService.list();
    }

    @ApiOperation(value = "更新员工套账")
    @PutMapping("/updateEmpSalary")
    public RespBean updateEmpSalary(Integer eid, Integer sid){
        if (employeeService.update(new UpdateWrapper<Employee>()
                .set("salaryId",sid)
                .eq("id",eid))) {
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }
}
